#include "form_uv_disinfection.h"
#include "ui_form_uv_disinfection.h"

// add nacessary includes here
#include "ui/share/form_prompt_dlg.h"
#include "ui/share/form_inquiry_dlg.h"
#include "ui/factory/uvc/form_light_lamp.h"

/*
 * Function:    FormUvDisinfection
 * Description: The default constructor
 * Paramer:     void
 * Return:
 */
FormUvDisinfection::FormUvDisinfection(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FormUvDisinfection)
{
    qDebug() << Q_FUNC_INFO;

    ui->setupUi(this);
}

/*
 * FormHistoryResult:    ~FormUvDisinfection
 * Description: The default destructor
 * Paramer:     void
 * Return:
 */
FormUvDisinfection::~FormUvDisinfection()
{
    qDebug() << Q_FUNC_INFO;

    delete ui;
}

/*
 * Function:    getInstance
 * Description: Get an instance of "FormUvDisinfection" class, if exist, return it
 * Paramer:     QWidget *pParent - the pointer of QWidget class
 * Return:      the pointer of "FormUvDisinfection" class
 */
FormUvDisinfection* FormUvDisinfection::getInstance(QWidget *pParent)
{
    static FormUvDisinfection *pNew = NULL;
    if(!pNew) {
        qDebug() << Q_FUNC_INFO;

        // Create a new object if it doesn't exist
        pNew = new FormUvDisinfection(pParent);
        if(NULL == pNew) return NULL;

        // After constructing object, initialize the object
        pNew->_initialze();

        // Initialize control's UI
        pNew->_initUi();

        // Hide widget firstly
        pNew->hide();
    }
    else {
        // Set the parent object
        pNew->setParent(pParent);
    }

    return pNew;
}

/*
 * Function:    _initialze
 * Description: After constructing object, initialize the object
 * Paramer:     void
 * Return:      void
 */
void FormUvDisinfection::_initialze()
{
    qDebug() << Q_FUNC_INFO;

    // Signal-slot initialization
    std::vector<bool> vecConnect;
    for(int i=0; i<(int)vecConnect.size(); i++) {
        Q_ASSERT(vecConnect.at(i));
    }
}

/*
* Function:		_initUi
* Description:	Init the window style
* Paramer:		void
* Return:		void
*/
void FormUvDisinfection::_initUi()
{
    qDebug() << Q_FUNC_INFO;

    // Displays the background image of the window
    QWidget::setAttribute(Qt::WA_StyledBackground);

    SET_STYLE_SHEET(QString(":/%1/factory/uvc/%2.qss").arg("skin_1").arg(this->objectName()));

    ui->pushButton_UV_Lample->setFocusPolicy(Qt::NoFocus);
}

/*
* Function:		changeEvent
* Description:	Triggers an event before it is switch language
* Paramer:		QShowEvent *event - the pointer of "QEvent"
* Return:		void
*/
void FormUvDisinfection::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
    {
        ui->retranslateUi(this);
        qDebug() << Q_FUNC_INFO;
        break;
    }
    default:
        break;
    }

    QWidget::changeEvent(e);
}

void FormUvDisinfection::on_pushButton_UV_Lample_clicked()
{
    // Show the inquiry dialog
    QString sPromptInfo = tr("Are you sure to turn on the UV light?");

    FormInquiryWidget::getInstance(this)->setInquiryInfo(sPromptInfo, E_WA_PROC_TURN_ON_UV_LIGHT);
    // Wait for the slotRespondInfoFromDlg function to respond
}

/*
* Function:		slotRespondInfoFromDlg
* Description:	Get the reply message from the child window
* Paramer:		int nReplyType - the reply type
*               bool bAccepted - is confirmed?
* Return:		void
*/
void FormUvDisinfection::slotRespondInfoFromDlg(int nReplyType, bool bAccepted)
{
    qDebug() << Q_FUNC_INFO << nReplyType << bAccepted;

    if(bAccepted) {
        switch (nReplyType) {
        case E_WA_PROC_TURN_ON_UV_LIGHT:
            FormLightLamp::getInstance()->setPromptInfo(tr("Shutdown"), tr("The UV light has been turned on and is being disinfected"), 30 * 60 * DEF_SEC_INTERVAL);
            break;
        default:
            break;
        }
    }
}
